Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

SourceDescription.setMediator   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 9.4285
1
var ExtensibleData = require('./ExtensibleData'),
2
    SourceCitation = require('./SourceCitation'),
3
    ResourceReference = require('./ResourceReference'),
4
    SourceReference = require('./SourceReference'),
5
    TextValue = require('./TextValue'),
6
    Note = require('./Note'),
7
    Attribution = require('./Attribution'),
8
    Coverage = require('./Coverage'),
9
    Identifiers = require('./Identifiers'),
10
    utils = require('./utils');
11
12
/**
13
 * A description of a source.
14
 * 
15
 * @constructor
16
 * @apram {Object} [json]
17
 */
18
var SourceDescription = function(json){
19
  
20
  // Protect against forgetting the new keyword when calling the constructor
21
  if(!(this instanceof SourceDescription)){
22
    return new SourceDescription(json);
23
  }
24
  
25
  // If the given object is already an instance then just return it. DON'T copy it.
26
  if(SourceDescription.isInstance(json)){
27
    return json;
28
  }
29
  
30
  ExtensibleData.call(this, json);
31
  
32
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
33
    this.setResourceType(json.resourceType);
34
    this.setCitations(json.citations);
35
    this.setMediaType(json.mediaType);
36
    this.setAbout(json.about);
37
    this.setMediator(json.mediator);
38
    this.setSources(json.sources);
39
    this.setAnalysis(json.analysis);
40
    this.setComponentOf(json.componentOf);
41
    this.setTitles(json.titles);
42
    this.setNotes(json.notes);
43
    this.setAttribution(json.attribution);
44
    this.setRights(json.rights);
45
    this.setCoverage(json.coverage);
46
    this.setDescriptions(json.descriptions);
47
    this.setIdentifiers(json.identifiers);
48
    this.setCreated(json.created);
49
    this.setModified(json.modified);
50
    this.setRepository(json.repository);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
51
  }
52
};
53
54
SourceDescription.prototype = Object.create(ExtensibleData.prototype);
55
56
SourceDescription._gedxClass = SourceDescription.prototype._gedxClass = 'GedcomX.SourceDescription';
57
58
/**
59
 * Check whether the given object is an instance of this class.
60
 * 
61
 * @param {Object} obj
62
 * @returns {Boolean}
63
 */
64
SourceDescription.isInstance = function(obj){
65
  return utils.isInstance(obj, this._gedxClass);
66
};
67
68
/**
69
 * Get the resource type
70
 * 
71
 * @returns {String}
72
 */
73
SourceDescription.prototype.getResourceType = function(){
74
  return this.resourceType;
75
};
76
77
/**
78
 * Set the resource type
79
 * 
80
 * @param {String} resourceType
81
 * @returns {SourceDescription}
82
 */
83
SourceDescription.prototype.setResourceType = function(resourceType){
84
  this.resourceType = resourceType;
85
  return this;
86
};
87
88
/**
89
 * Get the citations
90
 * 
91
 * @returns {SourceCitation[]}
92
 */
93
SourceDescription.prototype.getCitations = function(){
94
  return this.citations || [];
95
};
96
97
/**
98
 * Set the citations
99
 * 
100
 * @param {SourceCitation[]|Object[]} citations
101
 * @returns {SourceDescription}
102
 */
103
SourceDescription.prototype.setCitations = function(citations){
104
  if(Array.isArray(citations)){
105
    var description = this;
106
    description.citations = [];
107
    citations.forEach(function(citation){
108
      description.addCitation(citation);
109
    });
110
  }
111
  return this;
112
};
113
114
/**
115
 * Add a citation
116
 * 
117
 * @param {SourceCitation|Object} citation
118
 * @returns {SourceDescription}
119
 */
120
SourceDescription.prototype.addCitation = function(citation){
121
  if(citation){
122
    if(!Array.isArray(this.citations)){
123
      this.citations = [];
124
    }
125
    this.citations.push(SourceCitation(citation));
126
  }
127
  return this;
128
};
129
130
/**
131
 * Get the media type
132
 * 
133
 * @return {String}
134
 */
135
SourceDescription.prototype.getMediaType = function(){
136
  return this.mediaType;
137
};
138
139
/**
140
 * Set the media type
141
 * 
142
 * @param {String} mediaType
143
 * @returns {SourceDescription}
144
 */
145
SourceDescription.prototype.setMediaType = function(mediaType){
146
  this.mediaType = mediaType;
147
  return this;
148
};
149
150
/**
151
 * Get the about property
152
 * 
153
 * @returns {String}
154
 */
155
SourceDescription.prototype.getAbout = function(){
156
  return this.about;
157
};
158
159
/**
160
 * Set the about property
161
 * 
162
 * @param {String} about
163
 * @returns {SourceDescription}
164
 */
165
SourceDescription.prototype.setAbout = function(about){
166
  this.about = about;
167
  return this;
168
};
169
170
/**
171
 * Get the mediator
172
 * 
173
 * @returns {ResourceReference}
174
 */
175
SourceDescription.prototype.getMediator = function(){
176
  return this.mediator;
177
};
178
179
/**
180
 * Set the mediator
181
 * 
182
 * @param {ResourceReference} mediator
183
 * @returns {SourceDescription}
184
 */
185
SourceDescription.prototype.setMediator = function(mediator){
186
  if(mediator){
187
    this.mediator = ResourceReference(mediator);
188
  }
189
  return this;
190
};
191
192
/**
193
 * Get sources
194
 * 
195
 * @returns {SourceReference[]}
196
 */
197
SourceDescription.prototype.getSources = function(){
198
  return this.sources || [];
199
};
200
201
/**
202
 * Set the sources
203
 * 
204
 * @param {SourceReference[]|Object[]} sources
205
 * @returns {SourceDescription}
206
 */
207
SourceDescription.prototype.setSources = function(sources){
208
  if(Array.isArray(sources)){
209
    var description = this;
210
    description.sources = [];
211
    sources.forEach(function(source){
212
      description.addSource(source);
213
    });
214
  }
215
  return this;
216
};
217
218
/**
219
 * Add a source
220
 * 
221
 * @param {SourceReference|Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
222
 * @returns {SourceDescription}
223
 */
224
SourceDescription.prototype.addSource = function(source){
225
  if(source){
226
    if(!Array.isArray(this.sources)){
227
      this.sources = [];
228
    }
229
    this.sources.push(SourceReference(source));
230
  }
231
  return this;
232
};
233
234
/**
235
 * Get the analysis
236
 * 
237
 * @return {ResourceReference}
238
 */
239
SourceDescription.prototype.getAnalysis = function(){
240
  return this.analysis;
241
};
242
243
/**
244
 * Set the analysis
245
 * 
246
 * @param {ResourceReference|Object} analysis
247
 * @return {SourceDescription}
248
 */
249
SourceDescription.prototype.setAnalysis = function(analysis){
250
  if(analysis){
251
    this.analysis = ResourceReference(analysis);
252
  }
253
  return this;
254
};
255
256
/**
257
 * Get the componentOf property
258
 * 
259
 * @return {SourceReference}
260
 */
261
SourceDescription.prototype.getComponentOf = function(){
262
  return this.componentOf;
263
};
264
265
/**
266
 * Set the componentOf property
267
 * 
268
 * @param {SourceReference} componentOf
269
 */
270
SourceDescription.prototype.setComponentOf = function(componentOf){
271
  if(componentOf){
272
    this.componentOf = SourceReference(componentOf);
273
  }
274
  return this;
275
};
276
277
/**
278
 * Get titles
279
 * 
280
 * @returns {TextValue[]}
281
 */
282
SourceDescription.prototype.getTitles = function(){
283
  return this.titles || [];
284
};
285
286
/**
287
 * Set the titles
288
 * 
289
 * @param {TextValue[]|Object[]} titles
290
 * @returns {SourceDescription}
291
 */
292
SourceDescription.prototype.setTitles = function(titles){
293
  if(Array.isArray(titles)){
294
    var description = this;
295
    description.titles = [];
296
    titles.forEach(function(title){
297
      description.addTitle(title);
298
    });
299
  }
300
  return this;
301
};
302
303
/**
304
 * Add a title
305
 * 
306
 * @param {TextValue|Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
307
 * @returns {SourceDescription}
308
 */
309
SourceDescription.prototype.addTitle = function(title){
310
  if(title){
311
    if(!Array.isArray(this.titles)){
312
      this.titles = [];
313
    }
314
    this.titles.push(TextValue(title));
315
  }
316
  return this;
317
};
318
319
/**
320
 * Get notes
321
 * 
322
 * @returns {Note[]}
323
 */
324
SourceDescription.prototype.getNotes = function(){
325
  return this.notes || [];
326
};
327
328
/**
329
 * Set the notes
330
 * 
331
 * @param {Note[]|Object[]} notes
332
 * @returns {SourceDescription}
333
 */
334
SourceDescription.prototype.setNotes = function(notes){
335
  if(Array.isArray(notes)){
336
    var description = this;
337
    description.notes = [];
338
    notes.forEach(function(note){
339
      description.addNote(note);
340
    });
341
  }
342
  return this;
343
};
344
345
/**
346
 * Add a source
347
 * 
348
 * @param {Note|Object} note
349
 * @returns {SourceDescription}
350
 */
351
SourceDescription.prototype.addNote = function(note){
352
  if(note){
353
    if(!Array.isArray(this.notes)){
354
      this.notes = [];
355
    }
356
    this.notes.push(Note(note));
357
  }
358
  return this;
359
};
360
361
/**
362
 * Get the attribution
363
 * 
364
 * @returns {Attribution}
365
 */
366
SourceDescription.prototype.getAttribution = function(){
367
  return this.attribution;
368
};
369
370
/**
371
 * Set the attribution
372
 * 
373
 * @param {Attribution|Object} attribution
374
 * @returns {SourceDescription}
375
 */
376
SourceDescription.prototype.setAttribution = function(attribution){
377
  if(attribution){
378
    this.attribution = Attribution(attribution);
379
  }
380
  return this;
381
};
382
383
/**
384
 * Get the rights
385
 * 
386
 * @returns {ResourceReference[]}
387
 */
388
SourceDescription.prototype.getRights = function(){
389
  return this.rights || [];
390
};
391
392
/**
393
 * Set the rights
394
 * 
395
 * @param {ResourceReference[]|Object[]} rights
396
 * @returns {SourceDescription}
397
 */
398
SourceDescription.prototype.setRights = function(rights){
399
  if(Array.isArray(rights)){
400
    var description = this;
401
    description.rights = [];
402
    rights.forEach(function(right){
403
      description.addRight(right);
404
    });
405
  }
406
  return this;
407
};
408
409
/**
410
 * Add a source
411
 * 
412
 * @param {ResourceReference|Object} right
413
 * @returns {SourceDescription}
414
 */
415
SourceDescription.prototype.addRight = function(right){
416
  if(right){
417
    if(!Array.isArray(this.rights)){
418
      this.rights = [];
419
    }
420
    this.rights.push(ResourceReference(right));
421
  }
422
  return this;
423
};
424
425
/**
426
 * Get the coverage
427
 * 
428
 * @returns {Coverage}
429
 */
430
SourceDescription.prototype.getCoverage = function(){
431
  return this.coverage;
432
};
433
434
/**
435
 * Set the coverage
436
 * 
437
 * @param {Coverage|Object} coverage
438
 * @returns {SourceDescription}
439
 */
440
SourceDescription.prototype.setCoverage = function(coverage){
441
  if(coverage){
442
    this.coverage = Coverage(coverage);
443
  }
444
  return this;
445
};
446
447
/**
448
 * Get the descriptions
449
 * 
450
 * @returns {TextValue[]}
451
 */
452
SourceDescription.prototype.getDescriptions = function(){
453
  return this.descriptions || [];
454
};
455
456
/**
457
 * Set the descriptions
458
 * 
459
 * @param {TextValue[]|Object[]} descriptions
460
 * @returns {SourceDescription}
461
 */
462
SourceDescription.prototype.setDescriptions = function(descriptions){
463
  if(Array.isArray(descriptions)){
464
    var sourceDescr = this;
465
    sourceDescr.descriptions = [];
466
    descriptions.forEach(function(description){
467
      sourceDescr.addDescription(description);
468
    });
469
  }
470
  return this;
471
};
472
473
/**
474
 * Add a description
475
 * 
476
 * @param {TextValue|Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
477
 * @returns {SourceDescription}
478
 */
479
SourceDescription.prototype.addDescription = function(description){
480
  if(description){
481
    if(!Array.isArray(this.descriptions)){
482
      this.descriptions = [];
483
    }
484
    this.descriptions.push(TextValue(description));
485
  }
486
  return this;
487
};
488
489
/**
490
 * Get the identifiers
491
 * 
492
 * @returns {Identifiers}
493
 */
494
SourceDescription.prototype.getIdentifiers = function(){
495
  return this.identifiers;
496
};
497
498
/**
499
 * Set the identifiers
500
 * 
501
 * @param {Identifiers} identifiers
502
 * @returns {SourceDescription}
503
 */
504
SourceDescription.prototype.setIdentifiers = function(identifiers){
505
  if(identifiers){
506
    this.identifiers = Identifiers(identifiers);
507
  }
508
  return this;
509
};
510
511
/**
512
 * Get the created timestamp
513
 * 
514
 * @returns {Integer}
515
 */
516
SourceDescription.prototype.getCreated = function(){
517
  return this.created;
518
};
519
520
/**
521
 * Set the created timestamp
522
 * 
523
 * @param {Integer} created
524
 * @returns {SourceDescription}
525
 */
526
SourceDescription.prototype.setCreated = function(created){
527
  this.created = created;
528
  return this;
529
};
530
531
/**
532
 * Get the modified timestamp
533
 * 
534
 * @returns {Integer}
535
 */
536
SourceDescription.prototype.getModified = function(){
537
  return this.modified;
538
};
539
540
/**
541
 * Set the modified timestamp
542
 * 
543
 * @param {Integer} modified
544
 * @returns {SourceDescription}
545
 */
546
SourceDescription.prototype.setModified = function(modified){
547
  this.modified = modified;
548
  return this;
549
};
550
551
/**
552
 * Get the repository
553
 * 
554
 * @returns {ResourceReference}
555
 */
556
SourceDescription.prototype.getRepository = function(){
557
  return this.repository;
558
};
559
560
/**
561
 * Set the repository
562
 * 
563
 * @param {ResourceReference} repository
564
 * @returns {SourceDescription}
565
 */
566
SourceDescription.prototype.setRepository = function(repository){
567
  if(repository){
568
    this.repository = ResourceReference(repository);
569
  }
570
  return this;
571
};
572
573
/**
574
 * Export the object as JSON
575
 * 
576
 * @return {Object} JSON object
577
 */
578
SourceDescription.prototype.toJSON = function(){
579
  var json = ExtensibleData.prototype.toJSON.call(this);
580
  
581
  if(this.resourceType){
582
    json.resourceType = this.resourceType;
583
  }
584
  
585
  if(this.citations){
586
    json.citations = this.citations.map(function(c){
587
      return c.toJSON();
588
    });
589
  }
590
  
591
  if(this.mediaType){
592
    json.mediaType = this.mediaType;
593
  }
594
  
595
  if(this.about){
596
    json.about = this.about;
597
  }
598
  
599
  if(this.mediator){
600
    json.mediator = this.mediator.toJSON();
601
  }
602
  
603
  if(this.sources){
604
    json.sources = this.sources.map(function(s){
605
      return s.toJSON();
606
    });
607
  }
608
  
609
  if(this.analysis){
610
    json.analysis = this.analysis.toJSON();
611
  }
612
  
613
  if(this.componentOf){
614
    json.componentOf = this.componentOf.toJSON();
615
  }
616
  
617
  if(this.titles){
618
    json.titles = this.titles.map(function(t){
619
      return t.toJSON();
620
    });
621
  }
622
  
623
  if(this.notes){
624
    json.notes = this.notes.map(function(n){
625
      return n.toJSON();
626
    });
627
  }
628
  
629
  if(this.attribution){
630
    json.attribution = this.attribution.toJSON();
631
  }
632
  
633
  if(this.rights){
634
    json.rights = this.rights.map(function(r){
635
      return r.toJSON();
636
    });
637
  }
638
  
639
  if(this.coverage){
640
    json.coverage = this.coverage.toJSON();
641
  }
642
  
643
  if(this.descriptions){
644
    json.descriptions = this.descriptions.map(function(d){
645
      return d.toJSON();
646
    });
647
  }
648
  
649
  if(this.identifiers){
650
    json.identifiers = this.identifiers.toJSON();
651
  }
652
  
653
  if(this.created){
654
    json.created = this.created;
655
  }
656
  
657
  if(this.modified){
658
    json.modified = this.modified;
659
  }
660
  
661
  if(this.repository){
662
    json.repository = this.repository.toJSON();
663
  }
664
  
665
  return json;
666
};
667
668
module.exports = SourceDescription;